<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<fsButton ref="button" plain size="default" :buttons="buttons" @clickHandler="buttonHandler"></fsButton>
			</div>
			<div class="right-panel">
				<ex-search ref="search" :searches="searches" @searchOk="searchHandler" default-code="userCode" placeholder="请输入代岗人编码" :fixedParam="{}"></ex-search>
			</div>
		</el-header>
		<el-main class="nopadding">
			<ex-table id="checkTaskTable" ref="table" :tablename="'临时休假'" :columns="columns" :url="this.$API.system.tempLeave.page.url" :refs="this.$refs" search="search" @columnClick="columnClickHandler"></ex-table>
		</el-main>
	</el-container>
	<save-dialog ref="saveDialog" @success="searchHandler"/>
</template>

<script>
import saveDialog from '@/views/homePageDue/temporaryHoliday/save.vue'
import ExTable from "@/components/exTable/index.vue";
import ExSearch from "@/components/exSearch/index.vue";
import ExTreeNavigation from "@/components/exSearchTree/index.vue";
import ExSearchTree from "@/components/exSearchTree/index.vue";
import scSelectFilter from "@/components/scSelectFilter/index.vue";
import asset from "@/api/model/asset";
import tool from "@/utils/tool";
import BaseTemplate from "@/utils/baseTemplate";
export default {
	name: 'column',
	components: {
		scSelectFilter,
		ExSearchTree,
		ExTreeNavigation,
		ExSearch,
		ExTable,
		saveDialog,
	},
	data() {
		return {
			dialog: {
				save: false,
				permission: false,
			},
			apiObj: [],
			buttons: [
				{name: this.$t('button.add'), icon: "el-icon-plus", click: "add", permission: "add"},
				{name: "导出", icon: "el-icon-download", click: "export", type: "info", permission: "export"},
				{name: "重置", icon: "el-icon-delete", click: "rest", type: "info", permission: "rest"},
			],
			searches: [
				{type: "input", name: "姓名", code: "userName", placeholder: "请输入代岗人姓名", maxlength: 30, showLimit: true},
				{type: "input", name: "工号", code: "userCode", placeholder: "请输入代岗人工号"},
				{type: "select", name: "代岗状态", code: "replaceStatus", placeholder: "请选择代岗状态", dictCode:'REPLACE_JOB_STATUS'},
				{type: "daterange", name: "代岗日期", code: "replaceStartTime,replaceEndTime", placeholder: "请选择代岗日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
			],
			columns: [
				{code: "replaceStatus", name: "休假状态", width:"100",sortable: true,formatter:"DICT",key: "REPLACE_JOB_STATUS"},
				{code: "createUserName", name: "休假人", width:"150",sortable:true},
				{code: "createUserOrgId", name: "休假人所在部门", width:"220",sortable:true,formatter: "DICT",key: "SysOrganization"},
				{code: "userName", name: "代岗人名称", width:"150",sortable:true},
				{code: "userCode", name: "代岗人编码", width:"150",sortable:true},
				{code: "loginName", name: "代岗人账号", width:""},
				{code: "orgId", name: "代岗人所在部门", width:"220",sortable:true,formatter: "DICT",key: "SysOrganization"},
				{code: "mobile", name: "代岗人电话", width:"120"},
				{code: "email", name: "代岗人邮箱", width:"120"},
				{code: "replaceStartTime", name: "代岗开始时间", width:"110",sortable:true,formatter: "DATETIME"},
				{code: "replaceEndTime", name: "代岗结束时间", width:"110",sortable:true,formatter: "DATETIME"},
			],
			parentLevelCode:"",
			taskStatus:"",
			loginUsers: tool.current.user(),
		}
	},
	created() {
	},
	mounted() {
	},
	beforeMount() {

	},
	methods: {
		buttonHandler(index, name) {
			this.$options.methods[name](this, index);
		},
		async searchTreeHandler(data) {
			let queryParams = {pathCode:data.levelCode}
			this.parentLevelCode= data.levelCode;
			await this.$refs.table.refresh(queryParams);
		},

		async searchHandler() {
			let queryParams = {pathCode: this.parentLevelCode}
			queryParams.status = this.taskStatus;
			await this.$refs.table.refresh(queryParams);
		},
		columnClickHandler(name,data){
			this.$options.methods[name](this, data);
		},
		//添加
		add(_this) {
			let data = {
				parentLevelCode: _this.parentLevelCode,
				entityName:_this.$CONSTANT.entity.SysReplaceJob.name,
			};
			_this.$nextTick(() => {
				_this.$refs.saveDialog.open(data);
			})
		},
		//编辑
		edit(_this,index) {
			let row = _this.$refs.table.selectionOne();
			if (!row) {
				return;
			}
			if(!(row.createUser === _this.loginUsers.id)){
				_this.$message.warning("只能编辑自己的盘点任务");
				return;
			}
			_this.$nextTick(() => {
				_this.$refs.saveDialog.open(row);
			})
		},
		//查看
		show(_this) {
			let row = _this.$refs.table.selectionOne();
			if (!row) {
				return;
			}
			_this.$nextTick(() => {
				_this.$refs.viewDialog.open(row);
			})
		},
		//查看
		async show1(_this, row) {
			_this.$router.push({name:"checkDocumentPrepare",params:{fromRouteId:_this.$TOOL.crypto.MD5(_this.$route.path),checkTaskId:row.id}});
		},
		//重置
		rest(_this, index) {
			_this.$confirm(`是否重置休假信息`, '警告', {
				type: 'warning'
			}).then(async () => {
				_this.$refs.button.loading(index, true);
				var res = await _this.$API.system.tempLeave.rest.post({});
				if (res.code === 2000) {
					_this.$message.success(_this.$t("code."+res.code));
					_this.searchHandler();
				}
				_this.$refs.button.loading(index, false);
			}).catch(() => {
				_this.$refs.button.loading(index, false);
			});
		},
		//导出
		async export(_this,index) {
      let attachParams = {};
      let exportApi = _this.$API.system.tempLeave.export;
      let exTableRef = _this.$refs.table;
      let exportBtnRef = _this.$refs.button;
      let exportBtnIndex = index;
      await BaseTemplate.export(_this, exportApi, attachParams, exportBtnRef, exportBtnIndex, exTableRef);
		},
	}
}

</script>
<style scoped>

</style>
